<!-- 账号管理页 -- 许达 -- 2017年4月16日 -->
<template>
  <div >
    <!-- 查询条件 -->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;height:46px">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.queryUserName" size="small" placeholder="真实姓名" style="margin-top:2px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.queryLoginName" size="small" placeholder="登录名" style="margin-top:2px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.queryPhone" size="small" placeholder="联系方式" style="margin-top:2px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search" size="small" style="line-height:14px">查询</el-button>
        </el-form-item>
        <el-form-item class="button-align">
          <el-button type="primary" @click="handleAdd" :style="addFlag" size="small" v-if="getAuth(0) && this.loginType === 0">新增账号</el-button>
          <el-button type="primary" @click="handleAdd" :style="addFlag" size="small" v-if="getAuth(0) && this.loginType === 1">新增员工</el-button>
        </el-form-item>
        <el-form-item class="button-align">
          <el-button type="danger" @click="batchDelete" :disabled="this.sels.length===0" size="small" v-if="getAuth(3)">批量删除</el-button>
        </el-form-item>
        <el-form-item class="button-align">
          <el-button @click="showImport = true" :style="addFlag" size="small" v-if="!(currUser && currUser.type === 0) && (getAuth(1) && loginType === 0)">导入</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <!--列表-->
    <el-table :data="accountList" v-loading="listLoading" @selection-change="selsChange" border style="width: 100%; font-size: 12px;" row-class-name="tabRow">
      <el-table-column type="selection" v-if="getAuth(3)"></el-table-column>
      <el-table-column align="center" prop="userName" label="真实姓名" width="100"></el-table-column>
      <el-table-column align="center" label="登录名" width="120">
        <template scope="scope">
          {{scope.row.loginName}}<span style="color: red" v-show="scope.row.isAdmin">(管理员)</span>
        </template>
      </el-table-column>
      <el-table-column align="center" :formatter="formatSex" label="性别" width="60"></el-table-column>
      <el-table-column align="center" :formatter="formatCardType" label="证件类型" width="80"></el-table-column>
      <el-table-column align="center" prop="cardNo" label="证件号" ></el-table-column>
      <el-table-column align="center" prop="mail" label="邮箱" ></el-table-column>
      <el-table-column align="center" prop="phone" label=" 联系方式 " ></el-table-column>
      <el-table-column align="center" prop="qq" label="QQ"></el-table-column>
      <el-table-column align="center" prop="weixin" label="微信"></el-table-column>
      <el-table-column align="center" label="状态" width="80">
        <template scope="scope">
          <el-switch v-model="scope.row.status" @change="handleChangeStatus(scope.row)" on-color="#13ce66" off-color="#ff4949" v-if="getAuth(5)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column align="center" width="280" label="操作">
        <template scope="scope">
          <el-button size="small" type="primary" @click="handleDetail(scope.$index, scope.row)" v-if="getAuth(2)">详情</el-button>
          <el-button size="small" type="warning" @click="handleEdit(scope.$index, scope.row)" v-if="getAuth(2)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="getAuth(4)" v-show="!scope.row.isAdmin">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar" style="margin-top: 15px;" v-show="!listLoading">
      <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]" @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-size="pageSize" :current-page="page" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
    <!--新增/修改弹出层-->
    <el-dialog :title="dialogTitle" :visible.sync="showAdd" :close-on-click-modal="false" @close="resetAccount" >
      <el-form :model="account" label-width="90px" :rules="accountFormRules" ref="account" style="margin-top: -30px;">
        <el-form-item label="登录名" prop="loginName">
          <el-input v-model="account.loginName" :disabled="opType!=='add'" :maxlength="50" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="密码" v-if="opType==='add' || opType==='edit'" prop="password">
          <el-input v-model="account.password" type="password" :maxlength="50" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" v-if="opType==='add' || opType==='edit'" prop="confirmPass">
          <el-input v-model="account.confirmPass" type="password" :maxlength="50" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="真实姓名" prop="userName">
          <el-input v-model="account.userName" :disabled="isDetail && opType === 'detail'" :maxlength="50" size="mini"></el-input>
        </el-form-item>
        <el-form-item label="证件号" prop="cardNo">
          <el-col :span= "6">
            <el-select v-model="account.cardType" placeholder="请选择" size="mini" clearable change="handleChange" style="width: 120%;" :disabled="isDetail && opType === 'detail'">
              <el-option label="身份证" value="NI"></el-option>
              <el-option label="护照" value="PP" ></el-option>
              <el-option label="其他" value="OTHER"></el-option>
            </el-select>
          </el-col>
          <el-col :span="18" style="padding-left: 35px">
            <el-input v-model="account.cardNo" :disabled="isDetail && opType === 'detail'" :maxlength="50" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="性别" id="formheight">
          <el-radio-group v-model="account.sex" :disabled="isDetail && opType === 'detail'">
            <el-radio class="radio" :label="1">男</el-radio>
            <el-radio class="radio" :label="0">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="角色类型" prop="roleId">
          <el-select v-model="account.roleId" style="width: 100%" size="mini"  placeholder="角色类型" :disabled="isDetail && opType === 'detail'">
            <el-option v-for="(item, index) in roleList" :key="index" :label="item.roleName" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="部门类型" prop="deptId">
          <el-select v-model="account.deptId" style="width: 100%" size="mini"  placeholder="部门" :disabled="isDetail && opType === 'detail'" @change="getTeamList">
            <el-option v-for="(item, index) in deptList" :key="index" :label="item.deptName" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属团队" prop="treamId">
          <el-select v-model="account.treamId" style="width: 100%" size="mini"  placeholder="团队" :disabled="isDetail && opType === 'detail'">
            <el-option v-for="(item, index) in teamList" :key="index" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="邮箱" prop="mail">
          <el-input v-model="account.mail" size="mini" :disabled="isDetail && opType === 'detail'" :maxlength="50"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="account.phone" size="mini" :disabled="isDetail && opType === 'detail'" :maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="QQ">
          <el-input v-model="account.qq" size="mini" :disabled="isDetail && opType === 'detail'" :maxlength="50"></el-input>
        </el-form-item>
        <el-form-item label="微信">
          <el-input v-model="account.weixin" size="mini" :disabled="isDetail && opType === 'detail'" :maxlength="50"></el-input>
        </el-form-item>
      </el-form>
      <div scope="footer" class="dialog-footer" style="text-align: right;">
        <el-button @click.native="resetAccount">{{ opType === 'detail' ? '返回' : '取消' }}</el-button>
        <el-button type="primary" @click.native="handleSubmit" :loading="saveAccountLoading" v-if="opType!=='detail'">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="导入" :visible.sync="showImport" @close="handleRemove">
      <div>
        <a href="../../../static/file/notice/user.xlsx" download="user.xlsx">下载模板</a>
      </div>
      <el-upload ref="upload" class="upload-demo" drag action="/tour/web/baseAccount/upload.htm" :data="loginType1" :on-success="handlePreview"
                 :multiple="false" accept=".xls,.xlsx"  :auto-upload="false"  :file-list="fileList" :on-change="changeFun" :show-file-list="true" >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text"><em>请选择文件</em><br/>只能上传xls/xlsx文件</div>
        <!--<div class="el-upload__tip" slot="tip">{{fileList.length}}</div>-->
      </el-upload>
      <div scope="footer" class="dialog-center" style="text-align: center">
        <el-button @click="showImport = false">取 消</el-button>
        <el-button type="primary" @click="submitUpload" :loading="uploadLoading">开始导入</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
  import {buttonAuth, resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default {
    props: {
      operateType: String
    },
    data () {
      // 校验两次密码输入是否一致
      var validateConfirmPass = (rule, value, callback) => {
        if (this.opType === 'add') {
          if (value !== this.account.password) {
            callback(new Error('两次输入密码不一致!'))
          } else {
            callback()
          }
        } else {
          if (value !== this.account.password) {
            callback(new Error('两次输入密码不一致!'))
          } else {
            callback()
          }
        }
      }
      // 校验密码非空判断
      var checkPass = (rule, value, callback) => {
        if (this.opType === 'add') {
          if (value === '') {
            callback(new Error('请输入密码'))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      // 证件类型校验规则
      var validateCardType = (rule, value, callback) => {
        var cardType = this.account.cardType
        if (cardType === '' && value !== '') {
          this.account.cardNo = ''
          // callback(new Error('请选择证件类型!'))
        } else if (cardType !== '' && value === '') {
          callback(new Error('请输入证件号!'))
        } else {
          if (cardType === 'NI') {
            var para = {cardNo: value}
            this.$http.post('/smartLight/web/baseAccount/checkIDCard.htm', para).then(response => {
              var resBody = response.body
              if (resBody.isSuccess !== 0) {
                callback(new Error('请输入正确的身份证号码!'))
              } else {
                callback()
              }
            })
          } else if (cardType === 'PP') {
            var teg1 = new RegExp('^[DESPG]\\d{8}$')
            var teg2 = new RegExp('^[DSP]E\\d{7}$')
            if ((!teg1.test(value) && !teg2.test(value)) || value.trim === '') {
              callback(new Error('请输入正确的护照号码!'))
            } else {
              callback()
            }
          } else {
            callback()
          }
        }
      }
      // 证件号校验规则
      var validateCardNo = (rule, value, callback) => {
        var cardType = this.account.cardType
        if (cardType === '') {
          if (value !== '') {
            callback(new Error('请选择证件类型!'))
          } else {
            callback()
          }
        } else if (cardType === 'NI') {
          var para = {cardNo: value}
          this.$http.post('/smartLight/web/baseAccount/checkIDCard.htm', para).then(response => {
            var resBody = response.body
            if (resBody.isSuccess !== 0) {
              callback(new Error('请输入正确的身份证号码!'))
            } else {
              callback()
            }
          })
        } else if (cardType === 'PP') {
          var teg1 = new RegExp('^[DESPG]\\d{8}$')
          var teg2 = new RegExp('^[DSP]E\\d{7}$')
          if ((!teg1.test(value) && !teg2.test(value)) || value.trim === '') {
            callback(new Error('请输入正确的护照号码!'))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      // 登录名特殊字符验证
      var validateUserName = (rule, value, callback) => {
        var teg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        if (teg.test(value) || value.trim === '') {
          callback(new Error('请输入正确的真实姓名'))
        } else {
          callback()
        }
      }
      var validateLoginName = (rule, value, callback) => {
        var teg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        if (teg.test(value) || value.trim === '') {
          callback(new Error('请输入正确的登录名'))
        } else {
          callback()
        }
      }
      var validateRoleId = (rule, value, callback) => {
        if (value.length <= 0) {
          callback(new Error('请选择角色类型'))
        } else {
          callback()
        }
      }
      // 校验邮箱格式
      var validateMail = (rule, value, callback) => {
        if (value !== '') {
          var teg = new RegExp('^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$')
          if (!teg.test(value)) {
            callback(new Error('请输入正确的邮箱!'))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      // 校验联系方式格式
      var validatePhone = (rule, value, callback) => {
        if (value !== '') {
          var teg1 = new RegExp('^(\\d{11})$')
          var teg2 = new RegExp('^((\\d{3,4})-(\\d{7,8}))$')
          if (!teg1.test(value) && !teg2.test(value)) {
            callback(new Error('请输入正确的联系方式!'))
          } else {
            callback()
          }
        } else {
          callback()
        }
      }
      return {
        saveAccountLoading: false, // 新增修该保存按钮的加载动画按钮
        ischooseFile: false, // 是否选择上传文件
        isDetail: false, // 详情--内容只读
        uploadLoading: false, // 开始导入按钮的加载动画按钮
        menuIndex: 0,
        currUser: {},
        addFlag: '',
        accountList: [],
        total: 2,
        page: 1,
        pageSize: 10,
        count: 0,
        cardTypeArr: {'': '证件类型', 'NI': '身份证', 'PP': '护照', 'OTHER': '其他'},
        filters: {
          queryUserName: '',
          queryLoginName: '',
          queryPhone: ''
        },
        id: 0,
        sels: [], // 列表选中列
        listLoading: false,
        showAdd: false,
        addLoading: false,
        showImport: false,
        loginType: 0, // 当前账户登录类型
        operaType: 0, // 官网==0 运营管理供应（==1）门店（==2）账号时
        loginType1: {
          type: 0
        },
        fileList: [],
        account: {
          userName: '',
          loginName: '',
          cardType: '',
          cardNo: '',
          password: '',
          confirmPass: '',
          sex: 1,
          roleId: '',
          deptId: '',
          treamId: '',
          mail: '',
          phone: '',
          qq: '',
          weixin: '',
          status: 0,
          type: 0
        },
        roleList: [], // 角色集合
        deptList: [],
        teamList: [],
        opType: 'add',
        dialogTitle: this.loginType === 0 ? '新增账号' : '新增员工',
        accountFormRules: { // 用户信息校验
          userName: [
            {required: true, message: '请输入真实姓名', trigger: 'blur'},
            {validator: validateUserName}
          ],
          loginName: [
            {required: true, message: '请输入登录名', trigger: 'blur'},
            {validator: validateLoginName}
          ],
          password: [
            {required: true, validator: checkPass, trigger: 'blur'},
            {min: 6, max: 18, message: '请输入6~18个字符', trigger: 'blur'}
          ],
          roleId: [
            {validator: validateRoleId, required: true, trigger: 'change'}
          ],
          confirmPass: [
            {required: true, validator: validateConfirmPass, trigger: 'blur'}
          ],
          cardNo: [
            {validator: validateCardNo, trigger: 'blur'},
            {validator: validateCardType, trigger: 'change'}
          ],
          mail: [
            {validator: validateMail, trigger: 'change'}
          ],
          phone: [
            {validator: validatePhone, trigger: 'change'}
          ]
        },
        mdAccountButton: [441, 442, 443, 444, 445, 446], // 新增、编辑、删除、状态修改、导入、批量删除
        ebAccountButton: [558, 598, 560, 561, 559, 562], // 零售商家【新增，详情，编辑，批量删除,删除，修改状态】
        adminAccountButton: [414, 418, 415, 419, 416, 417] // 运营 【新增，导入，编辑，批量删除，删除，修改状态】
      }
    },
    methods: {
      checkIfLogin () { // 判断是否登录超时
        var user = sessionStorage.getItem('user')
        if (!user) {
          this.$alert('登录超时，请重新登录！', ' ', {
            type: 'warning'
          }).then(() => {
            this.$router.push({path: '/login'})
            sessionStorage.clear()
          })
        } else {
          return true
        }
      },
      submitUpload (file) {
        if (this.ischooseFile) {
          this.uploadLoading = true
          this.$refs.upload.submit()
        }
      },
      handleRemove (file, fileList) {
        this.$refs.upload.clearFiles()
        this.ischooseFile = false
      },
      handlePreview (response, file, fileList) {
        var res = JSON.parse(this.decode(response))
        this.uploadLoading = false
        if (res.res === 0) {
          this.$message({
            showClose: true,
            message: '成功添加' + res.num + '条数据',
            type: 'success'
          })
          this.showImport = false
          this.initAccountList()
        } else {
          this.$message({
            showClose: true,
            message: res.errorMsg,
            type: 'error'
          })
          this.$refs.upload.clearFiles()
        }
      },
      changeFun (file, fileList) {
        if (fileList.length > 1) {
//          this.$message({
//            showClose: true,
//            message: '只可以上传一个文件',
//            type: 'error'
//          })
//          this.$refs.upload.clearFiles()
          fileList.splice(0, 1)
        }
        if (fileList.length > 0) {
          this.ischooseFile = true
        }
      },
      // 分页插件查询方法-条数
      handleSizeChange (val) {
        this.pageSize = val
        this.initAccountList()
      },
      // 分页插件查询方法-页数
      handleCurrentChange (val) {
        this.page = val
        this.currentPage = val
        this.initAccountList()
      },
      // 初始化分页查询用户信息
      initAccountList () {
        this.listLoading = true
        var para = {
          pageNumber: this.page,
          pageSize: this.pageSize,
          userName: this.filters.queryUserName,
          loginName: this.filters.queryLoginName,
          phone: this.filters.queryPhone,
          type: this.loginType,
          op: 'page',
          operateType: this.operaType
        }
        this.$http.post('/smartLight/web/baseAccount/getList.htm', para).then(response => {
          var resBody = response.body
          this.listLoading = false
          if (resBody.isSuccess === 0) {
            this.total = resBody.result.totalElements
            this.accountList = resBody.result.content
            // autoHeight2() // iframe调整
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 状态转换
      formatStatus (row, column) {
        return row.status ? '正常' : '异常'
      },
      // 性别转换
      formatSex (row, column) {
        return row.sex === 1 ? '男' : '女'
      },
      // 证件类型转换
      formatCardType (row, column) {
        return this.cardTypeArr[row.cardType === '' ? ' ' : row.cardType]
      },
      // 【查询】
      search () {
        if (!this.checkIfLogin()) {
          return
        }
        this.page = 1
        this.initAccountList()
      },
      selsChange: function (sels) {
        this.sels = sels
      },
      handleChange: function (val) {
        this.account.cardType = val
      },
      // 【取消】，关闭弹出层
      resetAccount () {
        this.showAdd = false
        this.account = {
          userName: '',
          loginName: '',
          cardType: '',
          cardNo: '',
          password: '',
          confirmPass: '',
          sex: 1,
          roleId: '',
          treamId: '',
          mail: '',
          phone: '',
          qq: '',
          weixin: ''
        }
        this.$refs['account'].resetFields()
      },
      // 【新增】
      handleAdd () {
        this.showAdd = true
        this.opType = 'add'
        this.dialogTitle = '新增账号'
        this.$http.post('/smartLight/web/baseAccount/getRolesList.htm', {type: this.loginType}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.roleList = resBody.result
            console.log(resBody.result)
          }
        })
        this.$http.post('/smartLight/web/baseAccount/getDeptsList.htm', {}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.deptList = resBody.result
          }
        })
      },
      // 【提交】
      handleSubmit () {
        if (!this.checkIfLogin()) {
          return
        }
        this.$refs.account.validate((valid) => {
          if (valid) {
            var accountArr = []
            var account = {}
            var url = this.opType === 'add' ? '/smartLight/web/baseAccount/save.htm' : '/smartLight/web/baseAccount/update.htm'
            // 编辑（由于添加和更新的传参方式不同，此处分开处理）
            if (this.opType === 'edit') {
              account.id = this.account.id
              account.type = this.loginType // 当前登录账号的类型
              var fields = {
                loginName: this.account.loginName,
                mail: this.account.mail,
                qq: this.account.qq,
                sex: this.account.sex,
                password: this.account.password,
                userName: this.account.userName,
                cardType: this.account.cardType,
                weixin: this.account.weixin,
                cardNo: this.account.cardNo,
                phone: this.account.phone,
                type: this.account.type, // 所指定公司下的账号的类型
                roleId: this.account.roleId,
                deptId: this.account.deptId,
                treamId: this.account.treamId
              }
              account.op = 'update'
              account.fields = fields
              account.type = this.loginType
              accountArr.push(account)
            } else { // 新增
              account = Object.assign({}, this.account)
              account.roleId = this.account.roleId
              account.type = this.loginType
              account.createTime = new Date()
            }
            this.addLoading = true
            this.doUpdate(url, this.opType === 'edit' ? accountArr : account)
          }
        })
      },
      // 【新增】、【编辑】相应后台处理方法
      doUpdate (url, params) {
        this.saveAccountLoading = true
        this.$http.post(url, params).then(response => {
          this.saveAccountLoading = false
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.showAdd = false
            this.addLoading = false
            this.$message({
              showClose: true,
              message: '操作成功',
              type: 'success'
            })
            this.initAccountList()
            if (this.opType === 'edit') {
              var user = sessionStorage.getItem('user')
              if (user) {
                user = JSON.parse(user)
                if (user.id === this.account.id) { // 修改登录当前的用户，更新用户名
                  sessionStorage.setItem('user', JSON.stringify(this.account))
                  this.$store.dispatch('updateLoginName', this.account.userName)
                }
              }
            }
          } else if (resBody.isSuccess === 2) {
            this.listLoading = false
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      // 【编辑】
      handleEdit (index, row) {
        this.showAdd = true
        this.opType = 'edit'
        this.dialogTitle = this.loginType === 0 ? '修改账号' : '修改员工'
        this.account = Object.assign({}, row)
        // 查询当前公司的角色集合
        this.$http.post('/smartLight/web/baseAccount/getRolesList.htm', {type: this.loginType}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.roleList = resBody.result
          }
        })
        this.$http.post('/smartLight/web/baseAccount/getDeptsList.htm', {}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.deptList = resBody.result
          }
        })
        this.getTeamList()
      },
      getTeamList () {
        var para = {
          pageNumber: 1,
          pageSize: 10000,
          type: this.companytype,
          deptid: this.account.deptId
        }
        this.$http.post('/smartLight/web/sysTream/getList.htm', para).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.teamList = resBody.result.content
          }
        })
      },
      handleDetail (index, row) {
        this.showAdd = true
        this.isDetail = true
        this.opType = 'detail'
        this.dialogTitle = '员工信息详情'
        this.account = Object.assign({}, row)
        // 查询当前公司的角色集合
        this.$http.post('/smartLight/web/baseAccount/getRolesList.htm', {type: this.loginType}).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.roleList = resBody.result
          }
        })
      },
      // 【删除】按钮事件
      handleDelete (index, row) {
        var ids = []
        ids.push(row.id)
        this.deleteAccount(ids)
      },

      // 【批量删除】按钮事件
      batchDelete () {
        var ids = []
        this.sels.map(item => {
          ids.push(item.id)
        })
        this.deleteAccount(ids)
      },
      // 【删除】、【批量删除】执行方法
      deleteAccount (ids) {
        if (!this.checkIfLogin()) {
          return
        }
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.$http.post('/smartLight/web/baseAccount/deleteByIds.htm', ids + '|' + this.loginType).then(response => {
            var resBody = response.body
            if (resBody.isSuccess === 0) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.initAccountList()
            } else if (resBody.isSuccess === 2) {
              this.listLoading = false
              sessionOut(this) // session超时处理
            } else {
              this.$message({
                showClose: true,
                message: '操作失败',
                type: 'error'
              })
            }
          })
        }).catch(() => {})
      },
      handleChangeStatus (row) {
        var accountArr = []
        var account = {}
        account.id = row.id
        account.op = 'status'
        var fields = {status: row.status, type: row.type}
        account.fields = fields
        account.type = this.loginType // 当前登录账户的类型
        accountArr.push(account)
        this.doUpdate('/smartLight/web/baseAccount/update.htm', accountArr)
      },
      // 获取页面按钮权限
      getAuth (index) {
        return buttonAuth(index, this.loginType, this.adminAccountButton, this.ebAccountButton, this.mdAccountButton)
      }
    },
    mounted () {
      var user = sessionStorage.getItem('user')
      if (user) {
        this.currUser = user = JSON.parse(user)
        let opType = this.$route.query.type // 操作类型（员工账号）
        if (opType === 'companyAccount') {
          this.loginType = user.type // 当前登录账号的类型
        } else {
          this.loginType1.type = user.type
          this.operaType = this.operateType
        }
        // 浏览器向前或向后处理
        resetBreads(this)
        this.initAccountList()
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .tabRow
    font-size: 12px;
  .button-align
    float: right;
  .el-dialog--small
    width: 37% ;
  .prompt
    color: #ff4949
    line-height: 10px !important;
    display: block;

  #formheight
    margin: 14px 0;
    height: 38px;
    .el-form-item__content
      height: 30px;
      .el-form-item__error
        margin-top:3px
    .el-input
      height: 30px;
      .el-input__inner
        height: 30px;

  .borderStyle
    .el-input .el-input__inner {
      border-color: #ff4949 !important;
    }
  .cell
    padding-left: 0px !important
    padding-right 0px !important
    overflow: hidden !important
    text-overflow: ellipsis !important
    white-space: nowrap !important
    .el-checkbox {
      padding-left: 15px !important
    }
  #pagination
    background-color: transparent
    .el-input__inner
      width: 120px

</style>
<style lang="stylus" rel="stylesheet/stylus" scoped>
  .el-form-item{
    margin-bottom 10px
  }
</style>
